package cn.itcast.mapreduce_sort;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class SortReducer extends Reducer<PairWritable, Text, PairWritable, NullWritable> {
    private static enum Counter {
        REDUCE_INPUT_RECORDS, REDUCE_INPUT_VAL_NUMS
    }
    @Override
    protected void reduce(PairWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        context.getCounter(Counter.REDUCE_INPUT_RECORDS).increment(1l);
        for (Text value : values) {
            context.getCounter(Counter.REDUCE_INPUT_VAL_NUMS).increment(1l);
            context.write(key, NullWritable.get());
        }
    }
}
